<template>
  <div>
    <el-button type="text" @click="addFinance">新增</el-button>
    <el-button type="text" @click="deleteAssign">删除</el-button>
    <el-table
      highlight-current-row
      :data="tableData"
      @current-change="handleCurrentChange"
      style="width: 100%">
      <el-table-column
        prop="ynAssignName"
        label="人员">
      </el-table-column>
      <el-table-column
        prop="ynDay"
        label="日期">
      </el-table-column>
      <el-table-column
        prop="todayIncome"
        label="到账">
      </el-table-column>
      <el-table-column
        prop="effectiveVisits"
        label="有效出访">
      </el-table-column>
      <el-table-column
        prop="totalFollowups"
        label="5分钟以下">
      </el-table-column>
      <el-table-column
        prop="communicationOver10min"
        label="主动沟通10分钟以上">
      </el-table-column>
      <el-table-column
        prop="communicationOver5min"
        label="主动沟通5分钟以上">
      </el-table-column>
      <el-table-column
        prop="potentialCustomers"
        label="意向客户产出">
      </el-table-column>
      <el-table-column
        prop="newWechatFriends"
        label="新增微信">
      </el-table-column>
      <el-table-column
        prop="momentsPosted"
        label="朋友圈">
      </el-table-column>
    </el-table>

    <el-dialog :fullscreen="true" title="" width="80%" :visible.sync="dayFinanceDialog">
      <el-row>
        <el-col :span="8">

          <el-input
            type="textarea"
            :rows="2"
            :autosize="{ minRows: 8}"
            placeholder="请输入内容"
            v-model="dayFinanceForm.textarea">
          </el-input>
        </el-col>
        <el-col :span="16">
          <el-form :model="dayFinanceForm" label-width="30%" size="mini" label-position="right">
            <el-form-item label="名称">
              <el-input v-model="dayFinanceForm.ynAssignName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="日期">
              <el-date-picker
                v-model="dayFinanceForm.ynDay"
                format="yyyy-MM-dd"
                type="date"
                @change="changeDate"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="到账">
              <el-input v-model="dayFinanceForm.todayIncome" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="有效出访">
              <el-input-number v-model="dayFinanceForm.effectiveVisits" :min="0" label="有效出访"></el-input-number>
            </el-form-item>

            <el-form-item label="意向客户产出">
              <el-input-number v-model="dayFinanceForm.potentialCustomers" :min="0" label="意向客户产出"></el-input-number>
            </el-form-item>
            <el-form-item label="新增微信">
              <el-input-number v-model="dayFinanceForm.newWechatFriends" :min="0" label="新增微信"></el-input-number>
            </el-form-item>
            <el-form-item label="朋友圈">
              <el-input-number v-model="dayFinanceForm.momentsPosted" :min="0" label="朋友圈"></el-input-number>
            </el-form-item>
            <el-divider content-position="left">财税区</el-divider>
            <el-form-item label="主动沟通5分钟以下">
              <el-input-number v-model="dayFinanceForm.totalFollowups" :min="0" label="主动沟通5分钟以下"></el-input-number>
            </el-form-item>
            <el-form-item label="主动沟通10分钟以上">
              <el-input-number v-model="dayFinanceForm.communicationOver10min" :min="0"
                               label="主动沟通10分钟以上"></el-input-number>
            </el-form-item>
            <el-form-item label="主动沟通5分钟以上">
              <el-input-number v-model="dayFinanceForm.communicationOver5min" :min="0"
                               label="主动沟通5分钟以上"></el-input-number>
            </el-form-item>
            <el-form-item label="新增群">
              <el-input-number v-model="dayFinanceForm.newGroupChat" :min="0"
                               label="新增群"></el-input-number>
            </el-form-item>
            <el-form-item label="代转发">
              <el-input-number v-model="dayFinanceForm.repeatTransmit" :min="0"
                               label="代转发"></el-input-number>
            </el-form-item>

            <el-form-item label="大客户画像">
              <el-input-number v-model="dayFinanceForm.bigCustomer" :min="0"
                               label="大客户画像"></el-input-number>
            </el-form-item>

            <el-form-item label="今日合规意向">
              <el-input-number v-model="dayFinanceForm.complianceNum" :min="0"
                               label="今日合规意向"></el-input-number>
            </el-form-item>

            <el-form-item label="有业务客户收集">
              <el-input-number v-model="dayFinanceForm.busCustomer" :min="0"
                               label="有业务客户收集"></el-input-number>
            </el-form-item>

            <el-divider content-position="left">新开区</el-divider>
            <el-form-item label="有效通话">
              <el-input-number v-model="dayFinanceForm.communicationOver30s" :min="0"
                               label="有效通话"></el-input-number>
            </el-form-item>
          </el-form>

        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dayFinanceDialog = false">取 消</el-button>
        <el-button type="primary" size="small" @click="resolver">解 析</el-button>
        <el-button size="small" type="primary" @click="saveOrUpdate">保 存</el-button>
      </div>
    </el-dialog>

  </div>

</template>

<script>
import moment from 'moment';
import {Message} from "element-ui";

export default {
  name: "ynAssignDayFinance",
  created() {
    this.getynAssignDayFinance()
  },
  methods: {
    getynAssignDayFinance: function () {
      this.axios.post('/ynAssignDayFinance/list').then(res => {
        if (!!res.data.data) {
          this.tableData = res.data.data;
        }
      })
    },
    changeDate(val) {
      // this.form.ynDay = moment(val).format('yyyy-MM-dd');
    },
    cleanForm() {
      for (let key in this.dayFinanceForm) {
        this.dayFinanceForm[key] = ''
      }
      this.dayFinanceForm.ynDay = moment().format('yyyy-MM-DD');
    },
    saveOrUpdate() {
      this.axios.post('/ynAssignDayFinance/saveOrUpdate', {
        ...this.dayFinanceForm,
        ynDay: moment(this.dayFinanceForm.ynDay).format('yyyy-MM-DD')
      }).then(res => {
        if (200 === res.data.code) {
          Message.success('成功');
          this.getynAssignDayFinance();
          this.cleanForm();
          // this.dayFinanceDialog = false;
        }
      })
    },
    resolver() {
      this.axios.post('/ynAssignDayFinance/resolver', {
        textarea: this.dayFinanceForm.textarea
      }).then(res => {
        if (200 === res.data.code) {
          this.dayFinanceForm.ynAssignName = res.data.data.ynAssignName;
          this.dayFinanceForm.todayIncome = res.data.data.todayIncome;
          this.dayFinanceForm.effectiveVisits = res.data.data.effectiveVisits;
          this.dayFinanceForm.totalFollowups = res.data.data.totalFollowups;
          this.dayFinanceForm.communicationOver10min = res.data.data.communicationOver10min;
          this.dayFinanceForm.communicationOver5min = res.data.data.communicationOver5min;
          this.dayFinanceForm.potentialCustomers = res.data.data.potentialCustomers;
          this.dayFinanceForm.momentsPosted = res.data.data.momentsPosted;
          this.dayFinanceForm.newWechatFriends = res.data.data.newWechatFriends;
          this.dayFinanceForm.communicationOver30s = res.data.data.communicationOver30s;
          this.dayFinanceForm.bigCustomer = res.data.data.bigCustomer;
          this.dayFinanceForm.busCustomer = res.data.data.busCustomer;
          this.dayFinanceForm.complianceNum = res.data.data.complianceNum;
          this.dayFinanceForm.repeatTransmit = res.data.data.repeatTransmit;
          !!res.data.data.ynDay ? this.dayFinanceForm.ynDay = res.data.data.ynDay : null;
        }
      })
    },
    update() {
      this.addDialogFormVisible = true;
    },
    addFinance() {
      this.dayFinanceForm.ynDay = moment().format('yyyy-MM-DD');
      this.dayFinanceDialog = true;
    },
    deleteAssign() {
      this.axios.post('/ynAssignDayFinance/delete', this.currentRow).then(res => {
        if (200 === res.data.code) {
          this.getynAssignDayFinance();
          Message.success('成功');
        }
      })
    },
    changeRedio(vId) {
      let obj = {};
      obj = this.radioOptions.find((item) => {  //这里的radioPay就是上面遍历的数据源
        return item.id === vId;  //筛选出匹配数据，这里的value是你遍历数组每一项的value，如果没有对后台返回的数据做处理，一般为id
      });
      this.form.ynDepartmentName = obj.ynName;
      this.form.ynDepartment = obj.id;
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    }
  },
  data() {
    return {
      tableData: [],
      currentRow: null,
      form: {
        ynName: '',
        ynDepartment: '',
        ynAssignName: '',
        ynMonth: '',
        ynTarget: '',
      },
      dayFinanceForm: {
        ynAssignName: '',
        bigCustomer: '',
        complianceNum: '',
        busCustomer: '',
        ynDay: '',
        todayIncome: '',
        effectiveVisits: '',
        totalFollowups: '',
        communicationOver10min: '',
        communicationOver5min: '',
        communicationOver30s: '',
        potentialCustomers: '',
        momentsPosted: '',
        newWechatFriends: '',
        textarea: '',
        repeatTransmit: '',
        newGroupChat: '',
      },
      addDialogFormVisible: false,
      dayFinanceDialog: false,
      radioValue: '', // 选中的单选按钮的值
      radioOptions: [] // 存储从接口获取的数据
    }
  }
}
</script>

<style scoped>
</style>
